#include "pch.h"
#include "Vector.h"
namespace mini
{
	CVector3D::CVector3D()
	{
	}

	CVector3D::CVector3D(const CVector3D& v)
		: x(v.x), y(v.y), z(v.z)
	{

	}

	CVector3D::CVector3D(float* fArray)
		:x(fArray[0]), y(fArray[1]), z(fArray[2])
	{
	}

	CVector3D::CVector3D(float _x, float _y, float _z)
		:x(_x),y(_y),z(_z)
	{

	}

	CVector3D::CVector3D(const CVector3D&& v) noexcept
	{
		x = v.x;
		y = v.y;
		z = v.z;
	}

	CVector3D::~CVector3D()
	{
	}

	CVector3D & CVector3D::operator=(const CVector3D& v)
	{
		x = v.x;
		y = v.y;
		z = v.z;
		return *this;
	}

	CVector3D & CVector3D::operator=(CVector3D&& v) noexcept
	{
		x = v.x;
		y = v.y;
		z = v.z;
		return *this;
	}

	bool CVector3D::operator==(const CVector3D& v)
	{
		if ( ((x - v.x < 0.000001f) || (v.x - x < 0.000001f)) &&
			 ((y - v.y < 0.000001f) || (v.y - y < 0.000001f)) && 
			 ((z - v.z < 0.000001f) || (v.z - z < 0.000001f)) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	void CVector3D::zero()
	{
		x = y = z = 0.0f;
	}

	CVector3D CVector3D::operator-() const
	{
		return CVector3D(-x, -y, -x);
	}

	CVector3D CVector3D::operator+(const CVector3D& v)
	{
		return CVector3D(x + v.x, y + v.y, z + v.z);
	}

	CVector3D CVector3D::operator-(const CVector3D& v)
	{
		return CVector3D(x - v.x, y - v.y, z - v.z);
	}

	CVector3D CVector3D::operator+=(const CVector3D& v)
	{
		x += v.x;
		y += v.y;
		z += v.z;
		return *this;
	}

	CVector3D CVector3D::operator-=(const CVector3D& v)
	{
		x -= v.x;
		y -= v.y;
		z -= v.z;
		return *this;
	}

	CVector3D CVector3D::operator/(float fvalue)
	{
		float fTemp = 1 / fvalue;
		return CVector3D(x * fTemp, y * fTemp, z * fTemp);
	}

	CVector3D CVector3D::operator*(float fvalue)
	{
		return CVector3D(x * fvalue, y * fvalue, z * fvalue);
	}

	CVector3D CVector3D::operator*=(float fvalue)
	{
		x *= fvalue;
		y *= fvalue;
		z *= fvalue;
		return *this;
	}

	CVector3D CVector3D::operator/=(float fvalue)
	{
		float fTemp = 1 / fvalue;
		x *= fTemp;
		y *= fTemp;
		z *= fTemp;
		return *this;
	}

	void CVector3D::normal()
	{
		float magSq = x * x + y * y + z * z;
		if (magSq > 0.0f)
		{
			float fTemp = 1 / magSq;
			x *= fTemp;
			y *= fTemp;
			z *= fTemp;
		}
	}

}